package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EmployeeAccess;
import com.amsp.oa.oademo.service.EmployeeAccessService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/employee-access")
@Api(tags = "员工临时出入登记接口")
public class EmployeeAccessController {

    @Autowired
    private EmployeeAccessService employeeAccessService;

    @PostMapping("/save")
    @ApiOperation("保存员工临时出入记录")
    public ResponseEntity<Boolean> save(@RequestBody List<EmployeeAccess> records) {
        return ResponseEntity.ok(employeeAccessService.saveBatch(records));
    }

    @PutMapping("/update")
    @ApiOperation("更新员工临时出入记录")
    public ResponseEntity<Boolean> update(@RequestBody EmployeeAccess record) {
        return ResponseEntity.ok(employeeAccessService.updateById(record));
    }

    @GetMapping("/list")
    @ApiOperation("获取员工临时出入记录列表")
    public ResponseEntity<IPage<EmployeeAccess>> list(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) String employeeId,
            @RequestParam(required = false) String date) {
        IPage<EmployeeAccess> page = employeeAccessService.getPage(current, size, name, employeeId, date);

        return ResponseEntity.ok(page);
    }

    @GetMapping("/{id}")
    @ApiOperation("获取员工临时出入记录详情")
    public ResponseEntity<EmployeeAccess> getById(@PathVariable Long id) {
        return ResponseEntity.ok(employeeAccessService.getById(id));
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除员工临时出入记录")
    public ResponseEntity<Void> delete(@PathVariable Long id) {
        employeeAccessService.removeById(id);
        return ResponseEntity.ok().build();
    }
}